package com.leil.nio.channel;

import java.io.*;
import java.nio.channels.FileChannel;

/**
 * 使用transform复制文件
 */
public class FileChannelTransformDemo {

    public static void main(String[] args) {
        try {
            FileInputStream inputStream = new FileInputStream("d:/1.jpg");
            FileChannel inputChannel = inputStream.getChannel();

            FileOutputStream outputStream = new FileOutputStream("d:/2.jpg");
            FileChannel outputChannel = outputStream.getChannel();

            outputChannel.transferFrom(inputChannel, 0, inputChannel.size());

            System.out.println("copy success!!!");

            inputStream.close();
            inputChannel.close();

            outputStream.flush();
            outputStream.close();
            outputChannel.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
